/*
 * Academic License - for use in teaching, academic research, and meeting
 * course requirements at degree granting institutions only.  Not for
 * government, commercial, or other organizational use.
 *
 * File: SMO_Arctan_FOC_SMO_FOC.c
 *
 * Code generated for Simulink model 'SMO_Arctan_FOC'.
 *
 * Model version                  : 2.5
 * Simulink Coder version         : 9.8 (R2022b) 13-May-2022
 * C/C++ source code generated on : Wed Oct  9 21:48:48 2024
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include "rtwtypes.h"
#include "SMO_Arctan_FOC_SMO_FOC.h"
#include "rt_atan2f_snf.h"
#include "SMO_Arctan_FOC.h"
#include "rt_modf_snf.h"
#include <math.h>
#include "rt_nonfinite.h"
#include "SMO_Arctan_FOC_private.h"

/* Extern declarations from model 'SMO_Arctan_FOC' */
extern real32_T SMO_Arctan_FOC_arg_Target_Speed;/* '<Root>/Target_Speed' */
extern const real32_T *SMO_Arctan_FOC_arg_Iabc;/* '<Root>/Iabc' */
extern real32_T *SMO_Arctan_FOC_arg_Vabc_PU;/* '<Root>/Vabc_PU' */

/*
 * Output and update for action system:
 *    '<S11>/If Action Subsystem'
 *    '<S11>/If Action Subsystem3'
 */
void SMO_Arctan_FO_IfActionSubsystem(real32_T rtu_ERR, real32_T *rty_Zalpha)
{
  /* Product: '<S13>/Divide' incorporates:
   *  Constant: '<S13>/Constant'
   *  Constant: '<S13>/Constant1'
   *  Product: '<S13>/Product'
   */
  *rty_Zalpha = rtu_ERR * 0.65F / 1.2F;
}

/*
 * Output and update for action system:
 *    '<S11>/If Action Subsystem1'
 *    '<S11>/If Action Subsystem4'
 *    '<S42>/If Action Subsystem4'
 *    '<S42>/If Action Subsystem1'
 */
void SMO_Arctan_F_IfActionSubsystem1(real32_T *rty_Zalpha)
{
  /* SignalConversion generated from: '<S14>/Zalpha' incorporates:
   *  Constant: '<S14>/Constant'
   */
  *rty_Zalpha = 0.65F;
}

/*
 * Output and update for action system:
 *    '<S11>/If Action Subsystem2'
 *    '<S11>/If Action Subsystem5'
 *    '<S42>/If Action Subsystem5'
 *    '<S42>/If Action Subsystem2'
 */
void SMO_Arctan_F_IfActionSubsystem2(real32_T *rty_Zalpha)
{
  /* Gain: '<S15>/Gain' incorporates:
   *  Constant: '<S15>/Constant'
   */
  *rty_Zalpha = -0.65F;
}

/*
 * Output and update for action system:
 *    '<S32>/If Action Subsystem'
 *    '<S69>/If Action Subsystem'
 */
void SMO_Arctan__IfActionSubsystem_i(real32_T rtu_Theta, real32_T *rty_SMO_Theta)
{
  /* Sum: '<S33>/Add' incorporates:
   *  Constant: '<S33>/Constant'
   */
  *rty_SMO_Theta = rtu_Theta - 6.28318548F;
}

/*
 * Output and update for action system:
 *    '<S32>/If Action Subsystem1'
 *    '<S69>/If Action Subsystem1'
 */
void SMO_Arctan_IfActionSubsystem1_g(real32_T rtu_Theta, real32_T *rty_SMO_Theta)
{
  /* Sum: '<S34>/Add' incorporates:
   *  Constant: '<S34>/Constant'
   */
  *rty_SMO_Theta = rtu_Theta + 6.28318548F;
}

/*
 * Output and update for atomic system:
 *    '<S12>/atan2'
 *    '<S43>/atan2'
 */
void SMO_Arctan_FOC_atan2(real32_T rtu_A, real32_T rtu_B, real32_T *rty_Y,
  uint16_T rtp_outputUnit, B_atan2_SMO_Arctan_FOC_T *localB)
{
  real32_T rtb_Atan2;

  /* Trigonometry: '<S25>/Atan2' */
  rtb_Atan2 = rt_atan2f_snf(rtu_A, rtu_B);

  /* Outputs for Enabled SubSystem: '<S25>/If Action Subsystem' incorporates:
   *  EnablePort: '<S40>/Enable'
   */
  /* RelationalOperator: '<S38>/Compare' incorporates:
   *  Constant: '<S25>/Constant'
   *  Constant: '<S38>/Constant'
   */
  if (rtp_outputUnit == 1) {
    /* Gain: '<S41>/Gain' incorporates:
     *  Merge: '<S25>/Merge'
     *  SignalConversion generated from: '<S40>/In1'
     */
    localB->Merge = rtb_Atan2;
  }

  /* End of RelationalOperator: '<S38>/Compare' */
  /* End of Outputs for SubSystem: '<S25>/If Action Subsystem' */

  /* Outputs for Enabled SubSystem: '<S25>/per Uint' incorporates:
   *  EnablePort: '<S41>/Enable'
   */
  /* RelationalOperator: '<S39>/Compare' incorporates:
   *  Constant: '<S25>/Constant'
   *  Constant: '<S39>/Constant'
   */
  if (rtp_outputUnit == 2) {
    /* Gain: '<S41>/Gain' */
    localB->Merge = 0.159154937F * rtb_Atan2;

    /* Switch: '<S41>/Switch' */
    if (!(localB->Merge >= 0.0F)) {
      /* Gain: '<S41>/Gain' incorporates:
       *  Bias: '<S41>/Bias'
       *  Merge: '<S25>/Merge'
       */
      localB->Merge++;
    }

    /* End of Switch: '<S41>/Switch' */
  }

  /* End of RelationalOperator: '<S39>/Compare' */
  /* End of Outputs for SubSystem: '<S25>/per Uint' */

  /* AlgorithmDescriptorDelegate generated from: '<S25>/a16' */
  *rty_Y = localB->Merge;
}

/* System initialize for function-call system: '<S1>/SMO_FOC' */
void SMO_Arctan_FOC_SMO_FOC_Init(void)
{
  /* Start for SwitchCase: '<S8>/Switch Case' */
  SMO_Arctan_FOC_DW.SwitchCase_ActiveSubsystem = -1;
}

/* Enable for function-call system: '<S1>/SMO_FOC' */
void SMO_Arctan_FOC_SMO_FOC_Enable(void)
{
  SMO_Arctan_FOC_DW.SMO_FOC_RESET_ELAPS_T = true;

  /* Enable for DiscreteIntegrator: '<S11>/Discrete-Time Integrator' */
  SMO_Arctan_FOC_DW.DiscreteTimeIntegrator_SYSTEM_E = 1U;

  /* Enable for DiscreteIntegrator: '<S11>/Discrete-Time Integrator1' */
  SMO_Arctan_FOC_DW.DiscreteTimeIntegrator1_SYSTEM_ = 1U;

  /* Enable for DiscreteIntegrator: '<S117>/Integrator' */
  SMO_Arctan_FOC_DW.Integrator_SYSTEM_ENABLE = 1U;

  /* Enable for DiscreteIntegrator: '<S165>/Integrator' */
  SMO_Arctan_FOC_DW.Integrator_SYSTEM_ENABLE_m = 1U;

  /* Enable for DiscreteIntegrator: '<S42>/Discrete-Time Integrator' */
  SMO_Arctan_FOC_DW.DiscreteTimeIntegrator_SYSTEM_c = 1U;

  /* Enable for DiscreteIntegrator: '<S42>/Discrete-Time Integrator1' */
  SMO_Arctan_FOC_DW.DiscreteTimeIntegrator1_SYSTE_g = 1U;
}

/* Disable for function-call system: '<S1>/SMO_FOC' */
void SMO_Arctan_FOC_SMO_FOC_Disable(void)
{
  /* Disable for SwitchCase: '<S8>/Switch Case' */
  SMO_Arctan_FOC_DW.SwitchCase_ActiveSubsystem = -1;
}

/* Output and update for function-call system: '<S1>/SMO_FOC' */
void SMO_Arctan_FOC_SMO_FOC(void)
{
  real_T tmp;
  real32_T rtb_Add2_h;
  real32_T rtb_DTC;
  real32_T rtb_ERR;
  real32_T rtb_ERR_d;
  real32_T rtb_Merge1;
  real32_T rtb_Merge_f;
  real32_T rtb_Merge_l;
  real32_T rtb_Saturation;
  real32_T rtb_Sum1;
  real32_T rtb_Sum4;
  real32_T rtb_Switch_idx_0;
  real32_T rtb_ialpha;
  real32_T rtb_ibeta;
  uint32_T rtb_PositionToCount;
  uint32_T rtb_PositionToCount_b;
  uint16_T rtb_Get_Integer;
  int8_T rtPrevAction;
  if (SMO_Arctan_FOC_DW.SMO_FOC_RESET_ELAPS_T) {
    SMO_Arctan_FOC_DW.SMO_FOC_ELAPS_T = 0U;
  } else {
    SMO_Arctan_FOC_DW.SMO_FOC_ELAPS_T = rtmGetClockTick0() -
      SMO_Arctan_FOC_DW.SMO_FOC_PREV_T;
  }

  /* Update for IfAction SubSystem: '<S8>/Switch Case Action Subsystem1' incorporates:
   *  ActionPort: '<S196>/Action Port'
   */
  /* Outputs for IfAction SubSystem: '<S8>/Switch Case Action Subsystem1' incorporates:
   *  ActionPort: '<S196>/Action Port'
   */
  /* SwitchCase: '<S8>/Switch Case' */
  SMO_Arctan_FOC_DW.SMO_FOC_PREV_T = rtmGetClockTick0();

  /* End of Outputs for SubSystem: '<S8>/Switch Case Action Subsystem1' */
  /* End of Update for SubSystem: '<S8>/Switch Case Action Subsystem1' */
  SMO_Arctan_FOC_DW.SMO_FOC_RESET_ELAPS_T = false;

  /* Saturate: '<S9>/Saturation' incorporates:
   *  Delay: '<S9>/Delay'
   */
  if (SMO_Arctan_FOC_DW.Delay_DSTATE_a > 5000.0F) {
    rtb_Merge1 = 5000.0F;
  } else if (SMO_Arctan_FOC_DW.Delay_DSTATE_a < 10.0F) {
    rtb_Merge1 = 10.0F;
  } else {
    rtb_Merge1 = SMO_Arctan_FOC_DW.Delay_DSTATE_a;
  }

  /* End of Saturate: '<S9>/Saturation' */

  /* DiscreteIntegrator: '<S11>/Discrete-Time Integrator' */
  if (SMO_Arctan_FOC_DW.DiscreteTimeIntegrator_SYSTEM_E == 0) {
    /* DiscreteIntegrator: '<S11>/Discrete-Time Integrator' */
    SMO_Arctan_FOC_DW.DiscreteTimeIntegrator_DSTATE += 5.0E-5F * (real32_T)
      SMO_Arctan_FOC_DW.SMO_FOC_ELAPS_T
      * SMO_Arctan_FOC_DW.DiscreteTimeIntegrator_PREV_U;
  }

  /* End of DiscreteIntegrator: '<S11>/Discrete-Time Integrator' */

  /* MATLAB Function: '<S6>/Clark2' */
  rtb_ialpha = SMO_Arctan_FOC_arg_Iabc[0] * 2.0F / 3.0F -
    (SMO_Arctan_FOC_arg_Iabc[1] + SMO_Arctan_FOC_arg_Iabc[2]) / 3.0F;
  rtb_ibeta = (SMO_Arctan_FOC_arg_Iabc[1] - SMO_Arctan_FOC_arg_Iabc[2]) *
    1.73205078F / 3.0F;

  /* Sum: '<S11>/Sum' */
  rtb_ERR = SMO_Arctan_FOC_DW.DiscreteTimeIntegrator_DSTATE - rtb_ialpha;

  /* If: '<S11>/If' */
  if (rtb_ERR < 1.5F) {
    /* Outputs for IfAction SubSystem: '<S11>/If Action Subsystem' incorporates:
     *  ActionPort: '<S13>/Action Port'
     */
    SMO_Arctan_FO_IfActionSubsystem(rtb_ERR, &rtb_Merge_f);

    /* End of Outputs for SubSystem: '<S11>/If Action Subsystem' */
  } else if (rtb_ERR > 0.0F) {
    /* Outputs for IfAction SubSystem: '<S11>/If Action Subsystem1' incorporates:
     *  ActionPort: '<S14>/Action Port'
     */
    SMO_Arctan_F_IfActionSubsystem1(&rtb_Merge_f);

    /* End of Outputs for SubSystem: '<S11>/If Action Subsystem1' */
  } else {
    /* Outputs for IfAction SubSystem: '<S11>/If Action Subsystem2' incorporates:
     *  ActionPort: '<S15>/Action Port'
     */
    SMO_Arctan_F_IfActionSubsystem2(&rtb_Merge_f);

    /* End of Outputs for SubSystem: '<S11>/If Action Subsystem2' */
  }

  /* End of If: '<S11>/If' */

  /* Sum: '<S19>/Add' incorporates:
   *  Delay: '<S19>/Delay'
   *  Gain: '<S19>/Gain'
   *  Product: '<S19>/Product'
   *  Sum: '<S19>/Add1'
   */
  SMO_Arctan_FOC_DW.Delay_DSTATE_c += 5.0E-5F * rtb_Merge1 * (rtb_Merge_f -
    SMO_Arctan_FOC_DW.Delay_DSTATE_c);

  /* Gain: '<S20>/Gain' */
  rtb_ERR = 5.0E-5F * rtb_Merge1;

  /* DiscreteIntegrator: '<S11>/Discrete-Time Integrator1' */
  if (SMO_Arctan_FOC_DW.DiscreteTimeIntegrator1_SYSTEM_ == 0) {
    /* DiscreteIntegrator: '<S11>/Discrete-Time Integrator1' */
    SMO_Arctan_FOC_DW.DiscreteTimeIntegrator1_DSTATE += 5.0E-5F * (real32_T)
      SMO_Arctan_FOC_DW.SMO_FOC_ELAPS_T
      * SMO_Arctan_FOC_DW.DiscreteTimeIntegrator1_PREV_U;
  }

  /* End of DiscreteIntegrator: '<S11>/Discrete-Time Integrator1' */

  /* Sum: '<S11>/Sum1' */
  rtb_ERR_d = SMO_Arctan_FOC_DW.DiscreteTimeIntegrator1_DSTATE - rtb_ibeta;

  /* If: '<S11>/If1' */
  if (rtb_ERR_d < 1.5F) {
    /* Outputs for IfAction SubSystem: '<S11>/If Action Subsystem3' incorporates:
     *  ActionPort: '<S16>/Action Port'
     */
    SMO_Arctan_FO_IfActionSubsystem(rtb_ERR_d, &rtb_Merge1);

    /* End of Outputs for SubSystem: '<S11>/If Action Subsystem3' */
  } else if (rtb_ERR_d > 0.0F) {
    /* Outputs for IfAction SubSystem: '<S11>/If Action Subsystem4' incorporates:
     *  ActionPort: '<S17>/Action Port'
     */
    SMO_Arctan_F_IfActionSubsystem1(&rtb_Merge1);

    /* End of Outputs for SubSystem: '<S11>/If Action Subsystem4' */
  } else {
    /* Outputs for IfAction SubSystem: '<S11>/If Action Subsystem5' incorporates:
     *  ActionPort: '<S18>/Action Port'
     */
    SMO_Arctan_F_IfActionSubsystem2(&rtb_Merge1);

    /* End of Outputs for SubSystem: '<S11>/If Action Subsystem5' */
  }

  /* End of If: '<S11>/If1' */

  /* Sum: '<S20>/Add' incorporates:
   *  Delay: '<S20>/Delay'
   *  Product: '<S20>/Product'
   *  Sum: '<S20>/Add1'
   */
  SMO_Arctan_FOC_DW.Delay_DSTATE_i += (rtb_Merge1 -
    SMO_Arctan_FOC_DW.Delay_DSTATE_i) * rtb_ERR;

  /* Outputs for Atomic SubSystem: '<S12>/atan2' */
  SMO_Arctan_FOC_atan2(SMO_Arctan_FOC_DW.Delay_DSTATE_c,
                       SMO_Arctan_FOC_DW.Delay_DSTATE_i, &rtb_DTC, 1,
                       &SMO_Arctan_FOC_B.atan2_i);

  /* End of Outputs for SubSystem: '<S12>/atan2' */

  /* Sum: '<S23>/Add' incorporates:
   *  Constant: '<S12>/Constant'
   *  Constant: '<S23>/Constant1'
   *  Gain: '<S12>/Gain'
   *  Math: '<S12>/Math Function'
   */
  rtb_ERR = rt_modf_snf(-rtb_DTC, 6.28318548F) + 0.785398185F;

  /* If: '<S32>/If' */
  if (rtb_ERR > 6.2832F) {
    /* Outputs for IfAction SubSystem: '<S32>/If Action Subsystem' incorporates:
     *  ActionPort: '<S33>/Action Port'
     */
    SMO_Arctan__IfActionSubsystem_i(rtb_ERR, &rtb_ERR_d);

    /* End of Outputs for SubSystem: '<S32>/If Action Subsystem' */
  } else {
    /* Outputs for IfAction SubSystem: '<S32>/If Action Subsystem2' incorporates:
     *  ActionPort: '<S35>/Action Port'
     */
    /* SignalConversion generated from: '<S35>/Theta' */
    rtb_ERR_d = rtb_ERR;

    /* End of Outputs for SubSystem: '<S32>/If Action Subsystem2' */
  }

  /* End of If: '<S32>/If' */

  /* SwitchCase: '<S8>/Switch Case' */
  rtPrevAction = SMO_Arctan_FOC_DW.SwitchCase_ActiveSubsystem;
  SMO_Arctan_FOC_DW.SwitchCase_ActiveSubsystem = -1;
  tmp = trunc(SMO_Arctan_FOC_B.Motor_State);
  if (rtIsNaN(tmp) || rtIsInf(tmp)) {
    tmp = 0.0;
  } else {
    tmp = fmod(tmp, 4.294967296E+9);
  }

  switch (tmp < 0.0 ? -(int32_T)(uint32_T)-tmp : (int32_T)(uint32_T)tmp) {
   case 0:
    SMO_Arctan_FOC_DW.SwitchCase_ActiveSubsystem = 0;
    break;

   case 1:
    SMO_Arctan_FOC_DW.SwitchCase_ActiveSubsystem = 1;
    break;

   case 2:
    SMO_Arctan_FOC_DW.SwitchCase_ActiveSubsystem = 2;
    break;
  }

  switch (SMO_Arctan_FOC_DW.SwitchCase_ActiveSubsystem) {
   case 0:
    /* Outputs for IfAction SubSystem: '<S8>/Switch Case Action Subsystem' incorporates:
     *  ActionPort: '<S195>/Action Port'
     */
    /* Merge: '<S8>/Merge' incorporates:
     *  Constant: '<S195>/Constant1'
     *  SignalConversion generated from: '<S195>/Id_Ref'
     */
    SMO_Arctan_FOC_B.Merge = 1.0F;

    /* Merge: '<S8>/Merge1' incorporates:
     *  Constant: '<S195>/Constant'
     *  SignalConversion generated from: '<S195>/Iq_Ref'
     */
    SMO_Arctan_FOC_B.Merge1 = 0.0F;

    /* Merge: '<S8>/Merge2' incorporates:
     *  Constant: '<S195>/Constant2'
     *  SignalConversion generated from: '<S195>/Theta'
     */
    SMO_Arctan_FOC_B.Merge2 = 0.0F;

    /* End of Outputs for SubSystem: '<S8>/Switch Case Action Subsystem' */
    break;

   case 1:
    if (SMO_Arctan_FOC_DW.SwitchCase_ActiveSubsystem != rtPrevAction) {
      SMO_Arctan_FOC_DW.SwitchCaseActionSubsystem1_RESE = true;

      /* Enable for IfAction SubSystem: '<S8>/Switch Case Action Subsystem1' incorporates:
       *  ActionPort: '<S196>/Action Port'
       */
      /* Enable for SwitchCase: '<S8>/Switch Case' incorporates:
       *  DiscreteIntegrator: '<S196>/Discrete-Time Integrator'
       *  DiscreteIntegrator: '<S196>/Discrete-Time Integrator1'
       */
      SMO_Arctan_FOC_DW.DiscreteTimeIntegrator_SYSTEM_n = 1U;
      SMO_Arctan_FOC_DW.DiscreteTimeIntegrator1_SYSTE_m = 1U;

      /* End of Enable for SubSystem: '<S8>/Switch Case Action Subsystem1' */
    }

    /* Outputs for IfAction SubSystem: '<S8>/Switch Case Action Subsystem1' incorporates:
     *  ActionPort: '<S196>/Action Port'
     */
    if (SMO_Arctan_FOC_DW.SwitchCaseActionSubsystem1_RESE) {
      SMO_Arctan_FOC_DW.SwitchCaseActionSubsystem1_ELAP = 0U;
    } else {
      SMO_Arctan_FOC_DW.SwitchCaseActionSubsystem1_ELAP =
        SMO_Arctan_FOC_DW.SMO_FOC_PREV_T
        - SMO_Arctan_FOC_DW.SwitchCaseActionSubsystem1_PREV;
    }

    SMO_Arctan_FOC_DW.SwitchCaseActionSubsystem1_PREV =
      SMO_Arctan_FOC_DW.SMO_FOC_PREV_T;
    SMO_Arctan_FOC_DW.SwitchCaseActionSubsystem1_RESE = false;

    /* Merge: '<S8>/Merge' incorporates:
     *  Constant: '<S196>/Constant1'
     *  SignalConversion generated from: '<S196>/Id_Ref'
     */
    SMO_Arctan_FOC_B.Merge = 1.0F;

    /* Merge: '<S8>/Merge1' incorporates:
     *  Constant: '<S196>/Constant'
     *  SignalConversion generated from: '<S196>/Iq_Ref'
     */
    SMO_Arctan_FOC_B.Merge1 = 0.0F;

    /* DiscreteIntegrator: '<S196>/Discrete-Time Integrator' */
    if (SMO_Arctan_FOC_DW.DiscreteTimeIntegrator_SYSTEM_n == 0) {
      /* DiscreteIntegrator: '<S196>/Discrete-Time Integrator' */
      SMO_Arctan_FOC_DW.DiscreteTimeIntegrator_DSTATE_e += 5.0E-5F * (real32_T)
        SMO_Arctan_FOC_DW.SwitchCaseActionSubsystem1_ELAP *
        SMO_Arctan_FOC_DW.DiscreteTimeIntegrator_PREV_U_b;
    }

    /* End of DiscreteIntegrator: '<S196>/Discrete-Time Integrator' */

    /* DiscreteIntegrator: '<S196>/Discrete-Time Integrator1' */
    if (SMO_Arctan_FOC_DW.DiscreteTimeIntegrator1_SYSTE_m == 0) {
      /* DiscreteIntegrator: '<S196>/Discrete-Time Integrator1' */
      SMO_Arctan_FOC_DW.DiscreteTimeIntegrator1_DSTAT_l += 5.0E-5F * (real32_T)
        SMO_Arctan_FOC_DW.SwitchCaseActionSubsystem1_ELAP *
        SMO_Arctan_FOC_DW.DiscreteTimeIntegrator1_PREV__o;
    }

    /* End of DiscreteIntegrator: '<S196>/Discrete-Time Integrator1' */

    /* Merge: '<S8>/Merge2' incorporates:
     *  Constant: '<S196>/Constant4'
     *  Math: '<S196>/Math Function'
     *  SignalConversion generated from: '<S196>/Theta'
     */
    SMO_Arctan_FOC_B.Merge2 = rt_modf_snf
      (SMO_Arctan_FOC_DW.DiscreteTimeIntegrator1_DSTAT_l, 6.28318548F);

    /* Update for DiscreteIntegrator: '<S196>/Discrete-Time Integrator' */
    SMO_Arctan_FOC_DW.DiscreteTimeIntegrator_SYSTEM_n = 0U;
    SMO_Arctan_FOC_DW.DiscreteTimeIntegrator_PREV_U_b =
      SMO_Arctan_FOC_ConstB.Divide;

    /* Update for DiscreteIntegrator: '<S196>/Discrete-Time Integrator1' incorporates:
     *  Gain: '<S196>/Gain'
     *  Gain: '<S196>/Gain1'
     */
    SMO_Arctan_FOC_DW.DiscreteTimeIntegrator1_SYSTE_m = 0U;
    SMO_Arctan_FOC_DW.DiscreteTimeIntegrator1_PREV__o = 0.116666667F *
      SMO_Arctan_FOC_DW.DiscreteTimeIntegrator_DSTATE_e * 6.28318548F;

    /* End of Outputs for SubSystem: '<S8>/Switch Case Action Subsystem1' */
    break;

   case 2:
    /* Outputs for IfAction SubSystem: '<S8>/Switch Case Action Subsystem2' incorporates:
     *  ActionPort: '<S197>/Action Port'
     */
    /* Merge: '<S8>/Merge' incorporates:
     *  SignalConversion generated from: '<S197>/Id'
     */
    SMO_Arctan_FOC_B.Merge = SMO_Arctan_FOC_B.OutportBufferForId_Ref;

    /* Merge: '<S8>/Merge1' incorporates:
     *  SignalConversion generated from: '<S197>/Iq'
     */
    SMO_Arctan_FOC_B.Merge1 = SMO_Arctan_FOC_B.Saturation;

    /* Merge: '<S8>/Merge2' incorporates:
     *  SignalConversion generated from: '<S197>/SMO_Theta'
     */
    SMO_Arctan_FOC_B.Merge2 = rtb_ERR_d;

    /* End of Outputs for SubSystem: '<S8>/Switch Case Action Subsystem2' */
    break;
  }

  /* Gain: '<S191>/convert_pu' */
  rtb_ERR = 0.159154937F * SMO_Arctan_FOC_B.Merge2;

  /* If: '<S191>/If' incorporates:
   *  Constant: '<S192>/Constant'
   *  RelationalOperator: '<S192>/Compare'
   */
  if (rtb_ERR < 0.0F) {
    /* Outputs for IfAction SubSystem: '<S191>/If Action Subsystem' incorporates:
     *  ActionPort: '<S193>/Action Port'
     */
    /* DataTypeConversion: '<S193>/Convert_uint16' */
    rtb_Saturation = floorf(rtb_ERR);
    if (rtIsInfF(rtb_Saturation)) {
      rtb_Saturation = 0.0F;
    } else {
      rtb_Saturation = fmodf(rtb_Saturation, 65536.0F);
    }

    /* Sum: '<S193>/Sum' incorporates:
     *  DataTypeConversion: '<S193>/Convert_back'
     *  DataTypeConversion: '<S193>/Convert_uint16'
     */
    rtb_Add2_h = rtb_ERR - (real32_T)(rtb_Saturation < 0.0F ? (int32_T)(int16_T)
      -(int16_T)(uint16_T)-rtb_Saturation : (int32_T)(int16_T)(uint16_T)
      rtb_Saturation);

    /* End of Outputs for SubSystem: '<S191>/If Action Subsystem' */
  } else {
    /* Outputs for IfAction SubSystem: '<S191>/If Action Subsystem1' incorporates:
     *  ActionPort: '<S194>/Action Port'
     */
    /* DataTypeConversion: '<S194>/Convert_uint16' */
    rtb_Saturation = truncf(rtb_ERR);
    if (rtIsNaNF(rtb_Saturation) || rtIsInfF(rtb_Saturation)) {
      rtb_Saturation = 0.0F;
    } else {
      rtb_Saturation = fmodf(rtb_Saturation, 65536.0F);
    }

    /* Sum: '<S194>/Sum' incorporates:
     *  DataTypeConversion: '<S194>/Convert_back'
     *  DataTypeConversion: '<S194>/Convert_uint16'
     */
    rtb_Add2_h = rtb_ERR - (real32_T)(int16_T)(uint16_T)rtb_Saturation;

    /* End of Outputs for SubSystem: '<S191>/If Action Subsystem1' */
  }

  /* End of If: '<S191>/If' */

  /* Gain: '<S85>/indexing' */
  rtb_Add2_h *= 800.0F;

  /* DataTypeConversion: '<S85>/Get_Integer' */
  rtb_Saturation = truncf(rtb_Add2_h);
  if (rtIsNaNF(rtb_Saturation) || rtIsInfF(rtb_Saturation)) {
    rtb_Saturation = 0.0F;
  } else {
    rtb_Saturation = fmodf(rtb_Saturation, 65536.0F);
  }

  rtb_Get_Integer = (uint16_T)(rtb_Saturation < 0.0F ? (int32_T)(uint16_T)
    -(int16_T)(uint16_T)-rtb_Saturation : (int32_T)(uint16_T)rtb_Saturation);

  /* End of DataTypeConversion: '<S85>/Get_Integer' */

  /* Sum: '<S85>/Sum2' incorporates:
   *  DataTypeConversion: '<S85>/Data Type Conversion1'
   */
  rtb_ERR = rtb_Add2_h - (real32_T)rtb_Get_Integer;

  /* Selector: '<S85>/Lookup' incorporates:
   *  Constant: '<S85>/sine_table_values'
   *  Sum: '<S85>/Sum'
   */
  rtb_Sum1 = rtCP_sine_table_values_Value[rtb_Get_Integer];

  /* Sum: '<S190>/Sum4' incorporates:
   *  Constant: '<S85>/offset'
   *  Constant: '<S85>/sine_table_values'
   *  Product: '<S190>/Product'
   *  Selector: '<S85>/Lookup'
   *  Sum: '<S190>/Sum3'
   *  Sum: '<S85>/Sum'
   */
  rtb_Sum4 = (rtCP_sine_table_values_Value[(int32_T)(rtb_Get_Integer + 1U)] -
              rtb_Sum1) * rtb_ERR + rtb_Sum1;

  /* Selector: '<S85>/Lookup' incorporates:
   *  Constant: '<S85>/offset'
   *  Constant: '<S85>/sine_table_values'
   *  Sum: '<S190>/Sum5'
   *  Sum: '<S85>/Sum'
   */
  rtb_Sum1 = rtCP_sine_table_values_Value[(int32_T)(rtb_Get_Integer + 200U)];

  /* Sum: '<S190>/Sum6' incorporates:
   *  Constant: '<S85>/offset'
   *  Constant: '<S85>/sine_table_values'
   *  Product: '<S190>/Product1'
   *  Selector: '<S85>/Lookup'
   *  Sum: '<S190>/Sum5'
   *  Sum: '<S85>/Sum'
   */
  rtb_DTC = (rtCP_sine_table_values_Value[(int32_T)(rtb_Get_Integer + 201U)] -
             rtb_Sum1) * rtb_ERR + rtb_Sum1;

  /* Outputs for Atomic SubSystem: '<S6>/Park Transform' */
  /* Sum: '<S6>/Sum' incorporates:
   *  Product: '<S84>/acos'
   *  Product: '<S84>/bsin'
   *  Sum: '<S84>/sum_Ds'
   */
  rtb_ERR = SMO_Arctan_FOC_B.Merge - (rtb_ialpha * rtb_DTC + rtb_ibeta *
    rtb_Sum4);

  /* End of Outputs for SubSystem: '<S6>/Park Transform' */

  /* DiscreteIntegrator: '<S117>/Integrator' */
  if (SMO_Arctan_FOC_DW.Integrator_SYSTEM_ENABLE == 0) {
    /* DiscreteIntegrator: '<S117>/Integrator' */
    SMO_Arctan_FOC_DW.Integrator_DSTATE += 5.0E-5F * (real32_T)
      SMO_Arctan_FOC_DW.SMO_FOC_ELAPS_T * SMO_Arctan_FOC_DW.Integrator_PREV_U;
  }

  /* End of DiscreteIntegrator: '<S117>/Integrator' */

  /* Sum: '<S126>/Sum' incorporates:
   *  Gain: '<S122>/Proportional Gain'
   */
  rtb_Saturation = 0.194F * rtb_ERR + SMO_Arctan_FOC_DW.Integrator_DSTATE;

  /* Saturate: '<S124>/Saturation' */
  if (rtb_Saturation > 13.8564062F) {
    rtb_Saturation = 13.8564062F;
  } else if (rtb_Saturation < -13.8564062F) {
    rtb_Saturation = -13.8564062F;
  }

  /* End of Saturate: '<S124>/Saturation' */

  /* Outputs for Atomic SubSystem: '<S6>/Park Transform' */
  /* Sum: '<S6>/Sum1' incorporates:
   *  Product: '<S84>/asin'
   *  Product: '<S84>/bcos'
   *  Sum: '<S84>/sum_Qs'
   */
  rtb_Sum1 = SMO_Arctan_FOC_B.Merge1 - (rtb_ibeta * rtb_DTC - rtb_ialpha *
    rtb_Sum4);

  /* End of Outputs for SubSystem: '<S6>/Park Transform' */

  /* DiscreteIntegrator: '<S165>/Integrator' */
  if (SMO_Arctan_FOC_DW.Integrator_SYSTEM_ENABLE_m == 0) {
    /* DiscreteIntegrator: '<S165>/Integrator' */
    SMO_Arctan_FOC_DW.Integrator_DSTATE_b += 5.0E-5F * (real32_T)
      SMO_Arctan_FOC_DW.SMO_FOC_ELAPS_T * SMO_Arctan_FOC_DW.Integrator_PREV_U_e;
  }

  /* End of DiscreteIntegrator: '<S165>/Integrator' */

  /* Sum: '<S174>/Sum' incorporates:
   *  Gain: '<S170>/Proportional Gain'
   */
  rtb_Add2_h = 0.194F * rtb_Sum1 + SMO_Arctan_FOC_DW.Integrator_DSTATE_b;

  /* Saturate: '<S172>/Saturation' */
  if (rtb_Add2_h > 13.8564062F) {
    rtb_Add2_h = 13.8564062F;
  } else if (rtb_Add2_h < -13.8564062F) {
    rtb_Add2_h = -13.8564062F;
  }

  /* End of Saturate: '<S172>/Saturation' */

  /* Outputs for Atomic SubSystem: '<S6>/Inverse Park Transform' */
  /* Switch: '<S182>/Switch' incorporates:
   *  Product: '<S82>/dcos'
   *  Product: '<S82>/dsin'
   *  Product: '<S82>/qcos'
   *  Product: '<S82>/qsin'
   *  Sum: '<S82>/sum_alpha'
   *  Sum: '<S82>/sum_beta'
   */
  rtb_Switch_idx_0 = rtb_Saturation * rtb_DTC - rtb_Add2_h * rtb_Sum4;
  rtb_Sum4 = rtb_Add2_h * rtb_DTC + rtb_Saturation * rtb_Sum4;

  /* Gain: '<S188>/one_by_two' incorporates:
   *  AlgorithmDescriptorDelegate generated from: '<S82>/a16'
   */
  rtb_Add2_h = 0.5F * rtb_Switch_idx_0;

  /* Gain: '<S188>/sqrt3_by_two' incorporates:
   *  AlgorithmDescriptorDelegate generated from: '<S82>/a16'
   */
  rtb_DTC = 0.866025388F * rtb_Sum4;

  /* End of Outputs for SubSystem: '<S6>/Inverse Park Transform' */

  /* Sum: '<S188>/add_b' */
  rtb_Merge_l = rtb_DTC - rtb_Add2_h;

  /* Sum: '<S188>/add_c' */
  rtb_Add2_h = (0.0F - rtb_Add2_h) - rtb_DTC;

  /* Outputs for Atomic SubSystem: '<S6>/Inverse Park Transform' */
  /* Gain: '<S186>/one_by_two' incorporates:
   *  AlgorithmDescriptorDelegate generated from: '<S82>/a16'
   *  MinMax: '<S186>/Max'
   *  MinMax: '<S186>/Min'
   *  Sum: '<S186>/Add'
   */
  rtb_DTC = (fmaxf(fmaxf(rtb_Switch_idx_0, rtb_Merge_l), rtb_Add2_h) + fminf
             (fminf(rtb_Switch_idx_0, rtb_Merge_l), rtb_Add2_h)) * -0.5F;

  /* End of Outputs for SubSystem: '<S6>/Inverse Park Transform' */

  /* Sum: '<S185>/Add1' */
  rtb_Merge_l += rtb_DTC;

  /* Sum: '<S185>/Add2' */
  rtb_Add2_h += rtb_DTC;

  /* Outputs for Atomic SubSystem: '<S6>/Inverse Park Transform' */
  /* Sum: '<S185>/Add3' incorporates:
   *  AlgorithmDescriptorDelegate generated from: '<S82>/a16'
   */
  rtb_DTC += rtb_Switch_idx_0;

  /* End of Outputs for SubSystem: '<S6>/Inverse Park Transform' */

  /* Sum: '<S7>/Add' incorporates:
   *  Constant: '<S7>/Constant'
   *  Gain: '<S185>/Gain'
   *  Gain: '<S7>/Gain'
   */
  SMO_Arctan_FOC_arg_Vabc_PU[0] = 1.15470052F * rtb_DTC * 0.0360843912F + 0.5F;
  SMO_Arctan_FOC_arg_Vabc_PU[1] = 1.15470052F * rtb_Merge_l * 0.0360843912F +
    0.5F;
  SMO_Arctan_FOC_arg_Vabc_PU[2] = 1.15470052F * rtb_Add2_h * 0.0360843912F +
    0.5F;

  /* DiscreteIntegrator: '<S42>/Discrete-Time Integrator' */
  if (SMO_Arctan_FOC_DW.DiscreteTimeIntegrator_SYSTEM_c == 0) {
    /* DiscreteIntegrator: '<S42>/Discrete-Time Integrator' */
    SMO_Arctan_FOC_DW.DiscreteTimeIntegrator_DSTATE_o += 5.0E-5F * (real32_T)
      SMO_Arctan_FOC_DW.SMO_FOC_ELAPS_T
      * SMO_Arctan_FOC_DW.DiscreteTimeIntegrator_PREV_U_l;
  }

  /* End of DiscreteIntegrator: '<S42>/Discrete-Time Integrator' */

  /* If: '<S42>/If2' incorporates:
   *  Sum: '<S42>/Sum'
   */
  if (SMO_Arctan_FOC_DW.DiscreteTimeIntegrator_DSTATE_o - rtb_ialpha > 0.0F) {
    /* Outputs for IfAction SubSystem: '<S42>/If Action Subsystem1' incorporates:
     *  ActionPort: '<S46>/Action Port'
     */
    SMO_Arctan_F_IfActionSubsystem1(&rtb_DTC);

    /* End of Outputs for SubSystem: '<S42>/If Action Subsystem1' */
  } else {
    /* Outputs for IfAction SubSystem: '<S42>/If Action Subsystem2' incorporates:
     *  ActionPort: '<S47>/Action Port'
     */
    SMO_Arctan_F_IfActionSubsystem2(&rtb_DTC);

    /* End of Outputs for SubSystem: '<S42>/If Action Subsystem2' */
  }

  /* End of If: '<S42>/If2' */

  /* Outputs for Atomic SubSystem: '<S6>/Inverse Park Transform' */
  /* Gain: '<S42>/Gain1' incorporates:
   *  AlgorithmDescriptorDelegate generated from: '<S82>/a16'
   *  Sum: '<S42>/Add1'
   */
  rtb_ialpha = (rtb_Switch_idx_0 - rtb_DTC) * 10309.2783F;

  /* End of Outputs for SubSystem: '<S6>/Inverse Park Transform' */

  /* Sum: '<S50>/Add1' incorporates:
   *  Delay: '<S50>/Delay'
   */
  rtb_Saturation = rtb_DTC - SMO_Arctan_FOC_DW.Delay_DSTATE_g;

  /* Saturate: '<S10>/Saturation' incorporates:
   *  Delay: '<S10>/Delay'
   */
  if (SMO_Arctan_FOC_DW.Delay_DSTATE_gm > 2000.0F) {
    rtb_DTC = 2000.0F;
  } else if (SMO_Arctan_FOC_DW.Delay_DSTATE_gm < 10.0F) {
    rtb_DTC = 10.0F;
  } else {
    rtb_DTC = SMO_Arctan_FOC_DW.Delay_DSTATE_gm;
  }

  /* End of Saturate: '<S10>/Saturation' */

  /* Sum: '<S50>/Add' incorporates:
   *  Delay: '<S50>/Delay'
   *  Gain: '<S50>/Gain'
   *  Product: '<S50>/Product'
   */
  SMO_Arctan_FOC_DW.Delay_DSTATE_g += 5.0E-5F * rtb_DTC * rtb_Saturation;

  /* Sum: '<S54>/Add1' incorporates:
   *  Constant: '<S54>/Filter_Constant'
   *  Constant: '<S54>/One'
   *  Product: '<S54>/Product'
   *  Product: '<S54>/Product1'
   *  UnitDelay: '<S54>/Unit Delay'
   */
  SMO_Arctan_FOC_DW.UnitDelay_DSTATE = SMO_Arctan_FOC_DW.Delay_DSTATE_g * 0.15F
    + 0.85F * SMO_Arctan_FOC_DW.UnitDelay_DSTATE;

  /* Gain: '<S51>/Gain' */
  rtb_Saturation = 5.0E-5F * rtb_DTC;

  /* DiscreteIntegrator: '<S42>/Discrete-Time Integrator1' */
  if (SMO_Arctan_FOC_DW.DiscreteTimeIntegrator1_SYSTE_g == 0) {
    /* DiscreteIntegrator: '<S42>/Discrete-Time Integrator1' */
    SMO_Arctan_FOC_DW.DiscreteTimeIntegrator1_DSTAT_d += 5.0E-5F * (real32_T)
      SMO_Arctan_FOC_DW.SMO_FOC_ELAPS_T
      * SMO_Arctan_FOC_DW.DiscreteTimeIntegrator1_PREV__g;
  }

  /* End of DiscreteIntegrator: '<S42>/Discrete-Time Integrator1' */

  /* If: '<S42>/If1' incorporates:
   *  Sum: '<S42>/Sum1'
   */
  if (SMO_Arctan_FOC_DW.DiscreteTimeIntegrator1_DSTAT_d - rtb_ibeta > 0.0F) {
    /* Outputs for IfAction SubSystem: '<S42>/If Action Subsystem4' incorporates:
     *  ActionPort: '<S48>/Action Port'
     */
    SMO_Arctan_F_IfActionSubsystem1(&rtb_DTC);

    /* End of Outputs for SubSystem: '<S42>/If Action Subsystem4' */
  } else {
    /* Outputs for IfAction SubSystem: '<S42>/If Action Subsystem5' incorporates:
     *  ActionPort: '<S49>/Action Port'
     */
    SMO_Arctan_F_IfActionSubsystem2(&rtb_DTC);

    /* End of Outputs for SubSystem: '<S42>/If Action Subsystem5' */
  }

  /* End of If: '<S42>/If1' */

  /* Sum: '<S51>/Add' incorporates:
   *  Delay: '<S51>/Delay'
   *  Product: '<S51>/Product'
   *  Sum: '<S51>/Add1'
   */
  SMO_Arctan_FOC_DW.Delay_DSTATE_k += (rtb_DTC -
    SMO_Arctan_FOC_DW.Delay_DSTATE_k) * rtb_Saturation;

  /* Sum: '<S57>/Add1' incorporates:
   *  Constant: '<S57>/Filter_Constant'
   *  Constant: '<S57>/One'
   *  Product: '<S57>/Product'
   *  Product: '<S57>/Product1'
   *  UnitDelay: '<S57>/Unit Delay'
   */
  SMO_Arctan_FOC_DW.UnitDelay_DSTATE_n = SMO_Arctan_FOC_DW.Delay_DSTATE_k *
    0.15F + 0.85F * SMO_Arctan_FOC_DW.UnitDelay_DSTATE_n;

  /* Outputs for Atomic SubSystem: '<S43>/atan2' */
  SMO_Arctan_FOC_atan2(SMO_Arctan_FOC_DW.UnitDelay_DSTATE,
                       SMO_Arctan_FOC_DW.UnitDelay_DSTATE_n, &rtb_Merge_l, 1,
                       &SMO_Arctan_FOC_B.atan2_b);

  /* End of Outputs for SubSystem: '<S43>/atan2' */

  /* Math: '<S43>/Math Function' incorporates:
   *  Constant: '<S43>/Constant'
   *  Gain: '<S43>/Gain'
   */
  rtb_Merge_l = rt_modf_snf(-rtb_Merge_l, 6.28318548F);

  /* If: '<S69>/If' incorporates:
   *  Constant: '<S60>/Constant1'
   *  Sum: '<S60>/Add'
   */
  if (rtb_Merge_l + 0.785398185F > 6.2832F) {
    /* Outputs for IfAction SubSystem: '<S69>/If Action Subsystem' incorporates:
     *  ActionPort: '<S70>/Action Port'
     */
    SMO_Arctan__IfActionSubsystem_i(rtb_Merge_l + 0.785398185F, &rtb_Merge_l);

    /* End of Outputs for SubSystem: '<S69>/If Action Subsystem' */
  } else {
    /* Outputs for IfAction SubSystem: '<S69>/If Action Subsystem2' incorporates:
     *  ActionPort: '<S72>/Action Port'
     */
    /* SignalConversion generated from: '<S72>/Theta' */
    rtb_Merge_l += 0.785398185F;

    /* End of Outputs for SubSystem: '<S69>/If Action Subsystem2' */
  }

  /* End of If: '<S69>/If' */

  /* Gain: '<S24>/PositionToCount' */
  rtb_Saturation = truncf(6.83563648E+8F * rtb_ERR_d);
  if (rtIsNaNF(rtb_Saturation) || rtIsInfF(rtb_Saturation)) {
    rtb_Saturation = 0.0F;
  } else {
    rtb_Saturation = fmodf(rtb_Saturation, 4.2949673E+9F);
  }

  rtb_PositionToCount = rtb_Saturation < 0.0F ? (uint32_T)-(int32_T)(uint32_T)
    -rtb_Saturation : (uint32_T)rtb_Saturation;

  /* End of Gain: '<S24>/PositionToCount' */

  /* Sum: '<S28>/Add1' incorporates:
   *  Constant: '<S28>/Filter_Constant'
   *  Constant: '<S28>/One'
   *  DataTypeConversion: '<S37>/DTC'
   *  Delay: '<S24>/Delay'
   *  Gain: '<S12>/Gain1'
   *  Gain: '<S24>/SpeedGain'
   *  Product: '<S28>/Product'
   *  Product: '<S28>/Product1'
   *  Sum: '<S24>/SpeedCount'
   *  UnitDelay: '<S28>/Unit Delay'
   */
  SMO_Arctan_FOC_DW.UnitDelay_DSTATE_no = (real32_T)((int32_T)
    rtb_PositionToCount - (int32_T)
    SMO_Arctan_FOC_DW.Delay_DSTATE_n[SMO_Arctan_FOC_DW.CircBufIdx]) *
    9.31322575E-5F * 0.142857149F * 0.02F + 0.98F *
    SMO_Arctan_FOC_DW.UnitDelay_DSTATE_no;

  /* Sum: '<S31>/Add1' incorporates:
   *  Constant: '<S31>/Filter_Constant'
   *  Constant: '<S31>/One'
   *  Gain: '<S12>/f_2_we'
   *  Gain: '<S12>/n_2_f'
   *  Product: '<S31>/Product'
   *  Product: '<S31>/Product1'
   *  UnitDelay: '<S28>/Unit Delay'
   *  UnitDelay: '<S31>/Unit Delay'
   */
  SMO_Arctan_FOC_DW.Delay_DSTATE_a = 0.116666667F *
    SMO_Arctan_FOC_DW.UnitDelay_DSTATE_no * 6.28318548F * 0.02F + 0.98F *
    SMO_Arctan_FOC_DW.UnitDelay_DSTATE_c;

  /* Gain: '<S61>/PositionToCount' */
  rtb_Saturation = truncf(6.83563648E+8F * rtb_Merge_l);
  if (rtIsNaNF(rtb_Saturation) || rtIsInfF(rtb_Saturation)) {
    rtb_Saturation = 0.0F;
  } else {
    rtb_Saturation = fmodf(rtb_Saturation, 4.2949673E+9F);
  }

  rtb_PositionToCount_b = rtb_Saturation < 0.0F ? (uint32_T)-(int32_T)(uint32_T)
    -rtb_Saturation : (uint32_T)rtb_Saturation;

  /* End of Gain: '<S61>/PositionToCount' */

  /* Sum: '<S65>/Add1' incorporates:
   *  Constant: '<S65>/Filter_Constant'
   *  Constant: '<S65>/One'
   *  DataTypeConversion: '<S74>/DTC'
   *  Delay: '<S61>/Delay'
   *  Gain: '<S43>/Gain1'
   *  Gain: '<S61>/SpeedGain'
   *  Product: '<S65>/Product'
   *  Product: '<S65>/Product1'
   *  Sum: '<S61>/SpeedCount'
   *  UnitDelay: '<S65>/Unit Delay'
   */
  SMO_Arctan_FOC_DW.UnitDelay_DSTATE_m = (real32_T)((int32_T)
    rtb_PositionToCount_b - (int32_T)
    SMO_Arctan_FOC_DW.Delay_DSTATE_ca[SMO_Arctan_FOC_DW.CircBufIdx_n]) *
    9.31322575E-5F * 0.142857149F * 0.001F + 0.999F *
    SMO_Arctan_FOC_DW.UnitDelay_DSTATE_m;

  /* Sum: '<S68>/Add1' incorporates:
   *  Constant: '<S68>/Filter_Constant'
   *  Constant: '<S68>/One'
   *  Gain: '<S43>/f_2_we'
   *  Gain: '<S43>/n_2_f'
   *  Product: '<S68>/Product'
   *  Product: '<S68>/Product1'
   *  UnitDelay: '<S68>/Unit Delay'
   */
  SMO_Arctan_FOC_DW.Delay_DSTATE_gm = 0.116666667F *
    SMO_Arctan_FOC_DW.UnitDelay_DSTATE_m * 6.28318548F * 0.001F + 0.999F *
    SMO_Arctan_FOC_DW.UnitDelay_DSTATE_l;

  /* Update for DiscreteIntegrator: '<S11>/Discrete-Time Integrator' incorporates:
   *  AlgorithmDescriptorDelegate generated from: '<S82>/a16'
   *  Gain: '<S11>/Gain'
   *  Gain: '<S11>/Gain1'
   *  Sum: '<S11>/Add'
   *  Sum: '<S11>/Add1'
   */
  SMO_Arctan_FOC_DW.DiscreteTimeIntegrator_SYSTEM_E = 0U;

  /* Outputs for Atomic SubSystem: '<S6>/Inverse Park Transform' */
  SMO_Arctan_FOC_DW.DiscreteTimeIntegrator_PREV_U = ((rtb_Switch_idx_0 -
    SMO_Arctan_FOC_DW.Delay_DSTATE_c) - rtb_Merge_f) * 10309.2783F + -2000.0F *
    SMO_Arctan_FOC_DW.DiscreteTimeIntegrator_DSTATE;

  /* End of Outputs for SubSystem: '<S6>/Inverse Park Transform' */

  /* Update for DiscreteIntegrator: '<S11>/Discrete-Time Integrator1' incorporates:
   *  AlgorithmDescriptorDelegate generated from: '<S82>/a16'
   *  Gain: '<S11>/Gain2'
   *  Gain: '<S11>/Gain3'
   *  Sum: '<S11>/Add2'
   *  Sum: '<S11>/Add3'
   */
  SMO_Arctan_FOC_DW.DiscreteTimeIntegrator1_SYSTEM_ = 0U;

  /* Outputs for Atomic SubSystem: '<S6>/Inverse Park Transform' */
  SMO_Arctan_FOC_DW.DiscreteTimeIntegrator1_PREV_U = ((rtb_Sum4 -
    SMO_Arctan_FOC_DW.Delay_DSTATE_i) - rtb_Merge1) * 10309.2783F + -2000.0F *
    SMO_Arctan_FOC_DW.DiscreteTimeIntegrator1_DSTATE;

  /* End of Outputs for SubSystem: '<S6>/Inverse Park Transform' */

  /* Update for SwitchCase: '<S8>/Switch Case' */
  if (SMO_Arctan_FOC_DW.SwitchCase_ActiveSubsystem == 1) {
    /* Update for IfAction SubSystem: '<S8>/Switch Case Action Subsystem1' incorporates:
     *  ActionPort: '<S196>/Action Port'
     */
    SMO_Arctan_FOC_DW.SwitchCaseActionSubsystem1_PREV =
      SMO_Arctan_FOC_DW.SMO_FOC_PREV_T;
    SMO_Arctan_FOC_DW.SwitchCaseActionSubsystem1_RESE = false;

    /* End of Update for SubSystem: '<S8>/Switch Case Action Subsystem1' */
  }

  /* Update for DiscreteIntegrator: '<S117>/Integrator' incorporates:
   *  Gain: '<S114>/Integral Gain'
   */
  SMO_Arctan_FOC_DW.Integrator_SYSTEM_ENABLE = 0U;
  SMO_Arctan_FOC_DW.Integrator_PREV_U = 388.0F * rtb_ERR;

  /* Update for DiscreteIntegrator: '<S165>/Integrator' incorporates:
   *  Gain: '<S162>/Integral Gain'
   */
  SMO_Arctan_FOC_DW.Integrator_SYSTEM_ENABLE_m = 0U;
  SMO_Arctan_FOC_DW.Integrator_PREV_U_e = 388.0F * rtb_Sum1;

  /* Update for DiscreteIntegrator: '<S42>/Discrete-Time Integrator' incorporates:
   *  Gain: '<S42>/Gain'
   *  Sum: '<S42>/Add'
   */
  SMO_Arctan_FOC_DW.DiscreteTimeIntegrator_SYSTEM_c = 0U;
  SMO_Arctan_FOC_DW.DiscreteTimeIntegrator_PREV_U_l = -2000.0F *
    SMO_Arctan_FOC_DW.DiscreteTimeIntegrator_DSTATE_o + rtb_ialpha;

  /* Update for DiscreteIntegrator: '<S42>/Discrete-Time Integrator1' incorporates:
   *  AlgorithmDescriptorDelegate generated from: '<S82>/a16'
   *  Gain: '<S42>/Gain2'
   *  Gain: '<S42>/Gain3'
   *  Sum: '<S42>/Add2'
   *  Sum: '<S42>/Add3'
   */
  SMO_Arctan_FOC_DW.DiscreteTimeIntegrator1_SYSTE_g = 0U;

  /* Outputs for Atomic SubSystem: '<S6>/Inverse Park Transform' */
  SMO_Arctan_FOC_DW.DiscreteTimeIntegrator1_PREV__g = (rtb_Sum4 - rtb_DTC) *
    10309.2783F + -2000.0F * SMO_Arctan_FOC_DW.DiscreteTimeIntegrator1_DSTAT_d;

  /* End of Outputs for SubSystem: '<S6>/Inverse Park Transform' */

  /* Update for Delay: '<S24>/Delay' */
  SMO_Arctan_FOC_DW.Delay_DSTATE_n[SMO_Arctan_FOC_DW.CircBufIdx] =
    rtb_PositionToCount;
  if (SMO_Arctan_FOC_DW.CircBufIdx < 2U) {
    SMO_Arctan_FOC_DW.CircBufIdx++;
  } else {
    SMO_Arctan_FOC_DW.CircBufIdx = 0U;
  }

  /* End of Update for Delay: '<S24>/Delay' */

  /* Update for UnitDelay: '<S31>/Unit Delay' */
  SMO_Arctan_FOC_DW.UnitDelay_DSTATE_c = SMO_Arctan_FOC_DW.Delay_DSTATE_a;

  /* Update for Delay: '<S61>/Delay' */
  SMO_Arctan_FOC_DW.Delay_DSTATE_ca[SMO_Arctan_FOC_DW.CircBufIdx_n] =
    rtb_PositionToCount_b;
  if (SMO_Arctan_FOC_DW.CircBufIdx_n < 2U) {
    SMO_Arctan_FOC_DW.CircBufIdx_n++;
  } else {
    SMO_Arctan_FOC_DW.CircBufIdx_n = 0U;
  }

  /* End of Update for Delay: '<S61>/Delay' */

  /* Update for UnitDelay: '<S68>/Unit Delay' */
  SMO_Arctan_FOC_DW.UnitDelay_DSTATE_l = SMO_Arctan_FOC_DW.Delay_DSTATE_gm;
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
